package com.yuanfeng.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.util.querypage.PageUtils;
import com.yuanfeng.commoms.util.querypage.Query;
import com.yuanfeng.goods.entity.GoodsTagClassInfoEntity;
import com.yuanfeng.goods.entity.GoodsTagInfoEntity;
import com.yuanfeng.goods.mapper.GoodsTagClassInfoMapper;
import com.yuanfeng.goods.mapper.GoodsTagInfoMapper;
import com.yuanfeng.goods.service.GoodsTagClassInfoService;
import com.yuanfeng.goods.vo.CommunityArticleTagClassVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class GoodsTagClassInfoServiceImpl extends ServiceImpl<GoodsTagClassInfoMapper, GoodsTagClassInfoEntity>
    implements GoodsTagClassInfoService{

    @Autowired
    private GoodsTagInfoMapper goodsTagInfoMapper;
    @Override
    public ResponseResult deleteCommunityTopic(Map<String, Object> map) {
        Integer classId = Integer.valueOf(map.get("classId").toString());
        this.baseMapper.deleteById(classId);
        goodsTagInfoMapper.delete(new LambdaQueryWrapper<GoodsTagInfoEntity>().eq(GoodsTagInfoEntity::getClassId,classId));
        return ResponseResult.success(BizCodeEnume.OPERATION_SUCCESSFUL);
    }

    @Override
    public ResponseResult insertCommunityTopic(Map<String, Object> map) {
        //获取分类名称
        String className = map.get("className").toString();
        if (null != className){
            GoodsTagClassInfoEntity entity=new GoodsTagClassInfoEntity();
            entity.setClassName(className);
             this.baseMapper.insert(entity);
            return ResponseResult.success(BizCodeEnume.OPERATION_SUCCESSFUL);
        }
        return ResponseResult.success(BizCodeEnume.OPERATION_FAILED);
    }

    @Override
    public ResponseResult selectCommunityTopic(Map<String, Object> map) {
        IPage<GoodsTagClassInfoEntity> page=this.page(new Query<GoodsTagClassInfoEntity>().getPage(map),
                                            new LambdaQueryWrapper<GoodsTagClassInfoEntity>());
        return ResponseResult.success(PageUtils.getPage(page));
    }

    @Override
    public ResponseResult queryTagClass(Map<Object, Object> param) {
        List<CommunityArticleTagClassVO> tagClassList = this.baseMapper.queryTagClass();
        if (CollectionUtils.isEmpty(tagClassList)) {
            tagClassList = Lists.newArrayList();
        }
        return ResponseResult.success(tagClassList);
    }
}




